package sample;
import com.sun.java.swing.plaf.windows.resources.windows;
import javafx.scene.text.Text;

import java.awt.*;
import java.awt.event.*;
import java.sql.SQLOutput;

public class TestText {
    public static void main(String[] args) {
        //启动！
        MyFrame f = new MyFrame();
        f.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });


    }
}
class MyFrame extends Frame{
    public MyFrame()
    {
        TextField textField=new TextField();
        add(textField);
        //监听这个文本框输入的文字
        MyActionListener2 myActionListener2 = new MyActionListener2();
        textField.addActionListener(myActionListener2);
        setVisible(true);
        pack();
    }
}
class MyActionListener2 implements ActionListener
{

    @Override
    public void actionPerformed(ActionEvent actionEvent) {
        TextField field = (TextField) actionEvent.getSource();//得到资源，返回一个对象
        System.out.println(field.getText());//获取输入框的文本
        field.setText("");
    }
}


